cmake_minimum_required(VERSION 3.5)

#project(MainWindow LANGUAGES CXX)
set(GUI_LIB MainWindow)
#set(CMAKE_AUTOMOC ON)
#set(CMAKE_AUTOUIC ON)
#set(CMAKE_AUTORCC ON)
#
#set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
#
#find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
#find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)

#########################################################################
# 递归获取当前目录及其子目录中的所有 .h 文件
file(GLOB_RECURSE HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h")

set(INCLUDE_DIRS)
foreach(HEADER_FILE ${HEADER_FILES})
    get_filename_component(DIR ${HEADER_FILE} DIRECTORY)
    list(APPEND INCLUDE_DIRS ${DIR})
endforeach()

# 去除重复的路径
list(REMOVE_DUPLICATES INCLUDE_DIRS)

# 输出包含路径（可选，用于调试）
message(STATUS "Include directories: ${INCLUDE_DIRS}")

# 设置包含目录
include_directories(${INCLUDE_DIRS})

#########################################################################
# 递归获取当前目录及其子目录中的所有 .cpp 文件
file(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")

############################# 创建动态库 ######################################
add_library(${GUI_LIB} SHARED ${SOURCE_FILES} ${RESOURCE_FILES})


#target_compile_options(${GUI_LIB}
##        "$<${gcc_like_cxx}:-Wall;-Wextra;-Wshadow;-Wunused>"
##        "$<${msvc}:-W3>"
#)


# 根据不同编译器设置不同编译选项
target_compile_options(${GUI_LIB}
        PRIVATE
        $<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra -Wshadow -Wunused>
        $<$<CXX_COMPILER_ID:MSVC>:/W3>
)


#########################################################################
# 针对 Windows 平台的特殊设置
if (WIN32)
    target_compile_definitions(${GUI_LIB} PRIVATE BUILD_DATA_DEFINE_DLL)
endif()

# 设置库的包含目录和链接库
target_include_directories(${GUI_LIB} INTERFACE
        ${INCLUDE_DIRS}
        ${PYTHON_INCLUDE_DIR}
)

target_link_libraries(${GUI_LIB} PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_VERSION_MAJOR}::Gui
        Qt${QT_VERSION_MAJOR}::Widgets
        ${PYTHON_LIBRARIES}
)
